#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <search.h>
#include "../headers/all_purpose.h"
//# define VERY_LARGE 100
//# define SMALL 10
void adj_handle_yA_huA(char result[VERY_LARGE],char match_word[VERY_LARGE],char gender[SMALL] ,char number[SMALL] ){

 char *mark,*match_iyI,root_iyI[VERY_LARGE],tmp_result[VERY_LARGE];
        strcpy(tmp_result,"");
        mark = strchr(match_word,'~');
        int mark_posn = strlen(match_word)-strlen(mark);
        strncpy(tmp_result,match_word,mark_posn);
        char ch1 = match_word[(strlen(match_word)-strlen(mark)-1)];
	if ((ch1 == 'A') && (!strcmp(mark,"~huA"))){
                *(tmp_result + mark_posn) = '\0';
                if(!strcmp(tmp_result,"pExA")) {
                        if((!strcmp(gender,"m")) && (!strcmp(number,"s"))){
                                        strcpy(result,match_word);
                        }
                        if((!strcmp(gender,"m")) && (!strcmp(number,"p"))){
                                        strcat(tmp_result,"~hue");
                                        strcpy(result,tmp_result);
                        }
                        if((!strcmp(gender,"f"))){
                                        strcat(tmp_result,"~huI");
                                        strcpy(result,tmp_result);
                        }
                }
		else    {
                                *(tmp_result + mark_posn-1) = '\0';
                                if((!strcmp(gender,"m")) && (!strcmp(number,"s"))){
                                        strcpy(result,match_word);
                                }
                                if((!strcmp(gender,"m")) && (!strcmp(number,"p"))){
                                        strcat(tmp_result,"e~hue");
                                        strcpy(result,tmp_result);
                                }

				if((!strcmp(gender,"f"))){
                                                strcat(tmp_result,"I");
                                                if ((match_iyI = strstr(tmp_result,"iyI")) != NULL){
                                                        int mark_before_iyI= strlen(tmp_result)-strlen(match_iyI);
                                                        strncpy(root_iyI,tmp_result,mark_before_iyI);
                                                        *(root_iyI + mark_before_iyI) = '\0';
                                                        strcat(root_iyI,"I~huI");
                                                        strcpy(result,root_iyI);
                                                }
                                                else {
                                                        strcat(tmp_result,"~huI");
                                                        strcpy(result,tmp_result);
                                                }
                                }

                        }
                }
}

//main(int argc,char *argv[])
//{
//	char result[VERY_LARGE],str[VERY_LARGE],gender[SMALL],number[SMALL];

//	while(!feof(stdin)){	
//		scanf("%s\t%s\t%s",str,gender,number);
//		adj_handle_yA_huA(result,str,gender,number);
//		printf("%s\t%s\t%s\t%s\n",str,gender,number,result);
//	}
//}
	
